using System;
using System.Collections.Generic;
using System.Text;
//TODO: Documentation this class !!
namespace JobShopModel.Model.FactoryLvl
{
    /// <summary>
    /// Class time 
    /// Time can represent the duration of an element but also the time it should start
    /// </summary>
    class Time
    {
        /// <summary>
        /// 
        /// </summary>
        private int days = 0;

        /// <summary>
        /// 
        /// </summary>
        private double hours = 0;

        /// <summary>
        /// Default Constructor
        /// </summary>
        /// <param name="day"></param>
        /// <param name="hour"></param>
        public Time(int day, double hour)
        {
            Days = day;
            Hours = hour;
        }


        public Time(double hours)
        {
          new Time(0, hours);
        }

        /// <summary>
        /// Public Hours Properties.
        /// Automaticaly increments de days when added hours.
        /// </summary>
        public double Hours
        {
            set
            {
                if (value > 0.0)
                {
                    double tmp = hours + value;
                    if (tmp > 24)
                    {
                        this.days++;
                        this.hours = tmp % 24;
                    }
                }
            }
            get { return this.hours; }
        }

        /// <summary>
        /// </summary>
        public int Days
        {
            set
            {
                if (value > 0)
                {
                    this.days = value;
                }
            }

            get { return this.days; }
        }

        /// <summary>
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if ( !(obj is Time))
            {
                return false;
            }
            else
            {
                Time tmp = (Time)obj;
                if (tmp.Days == this.Days && tmp.Hours == this.Hours)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }


        public override int GetHashCode()
        {
            return base.GetHashCode();
        }


        public static bool operator < (Time t1,Time t2){
            return true;
        }

        public static bool operator >(Time t1, Time t2)
        {
            return true;
        }

        public static Time operator + (Time t1,Time t2)
        {
            return new Time((t1.Days + t2.Days), (t1.Hours + t2.Hours));
        }

        public static Time operator -(Time t1, Time t2)
        {
            return new Time((t1.Days - t2.Days), (t1.Hours - t2.Hours));
        }

        /// <summary>
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return "days: "+Days+" hours: "+Hours;
        }
    }
}
